/*图标显示动画效果 amber 2014-9-17*/
function imgHover(){
	var imgWid = 0 ;
	var imgHei = 0 ; //变量初始化
	var big = 1.2;//放大倍数
	$(".rightfunclist li").hover(
		function(){
			$(this).find("img").stop(true,true);
			var imgWid2 = 0;
			var imgHei2 = 0;//局部变量
			
			imgWid = $(this).find("img").width();
			imgHei = $(this).find("img").height();//保留初始量
			
			imgWid2 = imgWid * big;
			imgHei2 = imgHei * big;
			$(this).find("img").css({"z-index":2}); 
			$(this).find("img").animate({"width":imgWid2,"height":imgHei2,"margin-left":imgWid2/20,"margin-top":imgHei2/20});
		},
		function(){
			$(this).find("img").stop().animate({"width":imgWid,"height":imgHei,"margin-left":imgWid/20,"margin-top":imgHei/20,"z-index":0});});
}

/*取当前时间*/
function currentTime(){
	var d = new Date(),str = '';
	
	str += d.getFullYear()+'年';
	str += d.getMonth() + 1+'月';
	str += d.getDate()+'日&nbsp;';
	str += d.getHours()+'时'; 
	str += d.getMinutes()+'分'; 
	str += d.getSeconds()+'秒'; 
	
	return str;
}



/*生成绑定时效*/
function setMenuFunc(){

	$.each($("#menu_left ul li a"), function(i, it){
		//$(this).text();
		alert(i + $(this).text());
	});

	$("#menu_left ul li a").bind('click',function(){
		//alert("点击了");
		//alert($(this).attr("url"));
		$('#content').html('<iframe id="contentframe" width="100%" height="100%" src="' + $(this).attr("url") + 
				'" scrolling="auto" frameborder="0" marginheight="0" marginwidth="0" ></iframe>');
	});
}


/*显示主页*/
function showIndex(){
	reflashIframe('../dr/home.html');
}

/*只显示文本*/
function showcontent(item){
	$('#content').html('选择<a href="#"> ' + item.innerHTML + ' </a>菜单');
}

/*刷新iframe*/
function reflashIframe(url){
	$('#content').html('<iframe id="contentframe" width="100%" height="100%" src="' + url + 
		'" scrolling="auto" frameborder="0" marginheight="0" marginwidth="0" ></iframe>');

}

/*展示iframe*/
function showiframe(obj){
	//alert(obj.innerText);
	//alert(obj.attributes['url'].nodeValue);
	reflashIframe(obj.attributes['url'].nodeValue);

	if(obj.attributes['url'].nodeValue.toString() == "#"){
		showcontent(obj);
	}
}

/*显示一级标题首页*/
function showHome(){
	removeAllPanel();
	showIndex();
	$('#layoutdiv').layout();
	//折叠左边的面板
	$('#layoutdiv').layout('collapse','west');
}

/*加载本地JSON文件 */
function loadLocalJSON(index) {

	removeAllPanel();//首先移除项目
	
	if(index != 0){
		$('#layoutdiv').layout();
		//折叠左边的面板
		$('#layoutdiv').layout('expand','west');
	}else{
		showHome();
		return;
	}
	
	$.get("../../data/dr/dr.json", function(content){
		var json = $.parseJSON(content);
		//debugger;
		$.each(json.frame, function(i, item){
			if(index == i){
				addAllMenuAccordion(item.menu);
			}
		});
	});
}

function loadRemoteJSON(index, url){
	removeAllPanel();//首先移除项目
	
	if(index != 0){
		$('#layoutdiv').layout();
		//折叠左边的面板
		$('#layoutdiv').layout('expand','west');
	}else{
		showHome();
		return;
	}
	
	$.get(url, function(content){
		var json = $.parseJSON(content);
		//debugger;
		$.each(json.frame, function(i, item){
			if(index == item.index){
				addAllMenuAccordion(item.menu);
			}
		});
	});
}


/*加载本地JSON文件 */
function load4Menu(index) {

	removeAllPanel();//首先移除项目
	
	if(index != 0){
		$('#layoutdiv').layout();
		//折叠左边的面板
		$('#layoutdiv').layout('expand','west');
	}else{
		showHome();
		return;
	}
	
	$.get("../../data/dr/dr.json", function(content){
		var json = $.parseJSON(content);
		//debugger;
		$.each(json.frame, function(i, item){
			if(index == item.index){
				addAllMenuAccordion(item.menu);
			}
		});
	});

}


/*四级菜单加载*/
function openSubMenu() {
	var menuId = '#menu'+$(this).attr('id');
	var y = $(this).offset().top;
	var x = $(this).offset().left;
	$(menuId).menu({
		minWidth : 10
	}).menu('show', {
		left : x-16,
		top : y+26
	});
}

/*四级菜单关闭*/
function closeSubMenu() {
	var menu = $('#menu'+$(this).attr('id'));
	if(menu.length==0) return false;
	
	var offset = menu.offset();
	var top = offset.top;
	var left = offset.left;
	var bottom = top+menu.height();
	var right = left+menu.width();
	var x = event.x;
	var y = event.y+10;
	//alert("top="+top+",bottom="+bottom+",left="+left+",right="+right+",x="+x+",y="+y);
	if( x<left || x>right || y<top || y>bottom ){// 鼠标不在下拉菜单范围内，隐藏下拉菜单
		menu.menu('hide');
	}
}

/*当按钮点击时*/
function menuHandler(item){
	//alert(item.name);
	var id = "#" + item.name.replace('menu','');
	$(id).click();//设置主菜单点击
}

/*父子菜单时调用*/
function menuHandlerForIframe(item){
	var id = "#" + item.name.replace('menu','');
	var menu = $("#topframe").contents().find(id)[0].click();//设置主菜单点击
	//menu[0].click();
	/*找到菜单切换*/
	//menu.parent(".d2").siblings().attr("class", "d2");
	//menu.parent(".d2").attr("class", "d1");
}

/*遍历加入折叠面板*/
function addAllMenuAccordion(o){

	$.each(o, function(i, obj){
		addAccordion(obj);
	});
}


/*增加一个标签*/
function addAccordion(item){

	var htmlStr = '';

	//debugger;

	htmlStr += '<div title="' + item.secondMenuName + '"';

	if("true" == item.selectInit.toString()){
		htmlStr += ' data-options="selected:true" ';
	}

	htmlStr += ' style="padding:10px;"><ul>';

	$.each(item.thirdMenu, function(i, obj){
		//onclick="showiframe(this);"
		//class="easyui-linkbutton"  data-options="iconCls:\'icon-search\',plain:false"
		htmlStr += '<li><a href="javascript:void(0);" class="accor_li"  onclick="showiframe(this);" url="' + obj.url + '" >';
		htmlStr += obj.menuName + '</li>';
	}); 

	htmlStr += '</ul></div>';

	//alert(htmlStr);

	$('#menu_left').accordion('add',{
		title : item.secondMenuName,
		content : htmlStr
	});
}


/*增加面板*/
function addPanel(){
	$('#menu_left').accordion('add',{
		title:'Title',
		content:'<div style="padding:10px">Content'+idx+'</div>'
	});
}

/*删除所有面板*/
function removeAllPanel(){
	var pp = $('#menu_left').accordion('panels');

	$.each(pp, function(i, item){
		//var index = $('#menu_left').accordion('getPanelIndex',item);
		//$('#menu_left').accordion('remove',index);

		$('#menu_left').accordion('remove',0);
	}); 
}



/*
 * 各业务维护界面
 **/


/*在选中行后更新form中的数据*/
function setFormPropertisAfterSelectRow(){
	$("#datagrid1").datagrid({
		onSelect: function(rowIndex, rowData){
			loadData(rowData);
		},
		onClickRow: function(rowIndex, rowData){
			loadData(rowData);
		}
	});
}

/*加载数据*/
function loadData(obj){
	$('#ff').form('load',obj);
}

/*加载选中行的数据*/
function loadRowLocal(){
	var selected = $("#datagrid1").datagrid('getSelected');
	if (selected){
		loadData(obj);
	}
}

/*指定删除的最后一个字符*/
function delLastCharFormatStr(str,charType){
	if(str == null || str == ""){
		return "";
	}else{
		return str.substring(0,str.lastIndexOf(charType.toString()));
	}
}
/*重置form*/
function clearForm(){
	$('#ff').form('clear');
}

/*格式化json数据*/
function formatJSONData(row) {

	var xs = [], arr_, row_;
	for ( var p in row) {
		xs.push('"' + p + '" : "' + row[p] + ' "');
	}
	xs = '{ ' + xs.join(' , ') + '}';
	row_ = xs;
	arr_.push(row_);
	
	return arr_;
}